package dian.com.mvvmdemo.login


import android.view.View
import androidx.lifecycle.Observer
import dian.com.mvvmdemo.R
import dian.com.mvvmdemo.http.base.BaseViewModelActivity
import dian.com.mvvmdemo.http.databean.loginData
import kotlinx.android.synthetic.main.activity_login.*

/*
 *
 *Created by QingDian_Fan on 2019/11/18
 * */
class LoginActivity : BaseViewModelActivity<LoginViewModel>(), View.OnClickListener {


    private lateinit var data: loginData

    override fun getLayoutId(): Int = R.layout.activity_login

    override fun providerVMClass(): Class<LoginViewModel>? = LoginViewModel::class.java

    override fun initView() {

    }

    override fun initData() {
        login.setOnClickListener(this)
        viewModel.getLogin().observe(this, Observer {
            if (it.errorCode == 0) {
                showToast("登录成功")

            } else {
                showToast("账号或密码错误")
            }
        })
    }

    override fun onClick(v: View?) {
        when (v!!.id) {
            R.id.login -> {
                val name = username.text.toString()
                val pwd = password.text.toString()

                viewModel.loginDatas(name, pwd);

            }
        }
    }

}
